package org.jeecg.modules.quartz.job;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.util.DateUtils;
import org.jeecg.modules.fund.entity.DayCount;
import org.jeecg.modules.fund.entity.UserhomeFund;
import org.jeecg.modules.fund.mapper.FundMapper;
import org.jeecg.modules.fund.mapper.UserhomeFundMapper;
import org.jeecg.modules.fund.service.IDayCountService;
import org.jeecg.modules.fund.service.IUserhomeFundService;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;

import org.jeecg.common.util.oConvertUtils;
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * 示例不带参定时任务
 * 
 * @Author Scott
 */
@Slf4j
public class CountJob implements Job {



	@Autowired
	private IDayCountService dayCountService;

	@Override
	public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
		log.info(" Job Execution key："+jobExecutionContext.getJobDetail().getKey());
		Date currentDate = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		String dateString = dateFormat.format(currentDate);
		LambdaQueryWrapper<DayCount> queryWrapper=new LambdaQueryWrapper<>();
		queryWrapper.eq(DayCount::getCountTime,dateString);
		DayCount dayCount=dayCountService.getOne(queryWrapper);
		DayCount tempDayCountCount=dayCountService.totayCountStatic();
		if(oConvertUtils.isNotEmpty(dayCount))
		{
			dayCount.setTodayFund(tempDayCountCount.getTodayFund());
			dayCount.setBalanceFund(tempDayCountCount.getBalanceFund());
			dayCount.setTotalFund(tempDayCountCount.getTotalFund());
			dayCountService.updateById(dayCount);
		}
		else
		{
			dayCountService.save(tempDayCountCount);
		}
		log.info(String.format(" Jeecg-Boot 普通定时任务 CountJob !  时间:" + DateUtils.getTimestamp()));
	}
}
